<?php
/**
 * @version $Id: Wordlist.php 174 2008-02-24 15:56:02Z mikhail.miguel $
 */

require_once dirname(dirname(dirname(dirname(__FILE__)))).'/lib/trackback/spamcheck.php';

class SpamCheck_Wordlist extends SpamCheck {

    var $_options = array(
        'sources'       => array(
        ),
        'elements'      => array(
            'title',
            'excerpt',
            'blog_name'
        ),
        'comparefunc' => array('SpamCheck_Wordlist', '_stripos')
    );

    function SpamCheck_Wordlist($options = null) {
        if (is_array($options)) {
            foreach ($options as $key => $val) {
                $this->_options[$key] = $val;
            }
        }
    }

    function _checkSource(&$source, $trackback)
    {
        foreach ($this->_options['elements'] as $element) {
            if(TrackbackService::isError($item = $trackback->get($element))) {
                return TrackbackService::setError($item->getMessage().'<br />'.' Cannot procede without it.');
            }
            $elements[$element] = $item;
        }
        foreach ($elements as $element) {
            if (false !== call_user_func($this->_options['comparefunc'], $source, $element)) {
                return TrackbackService::setError('Your comments contains a spammy word.');
            }
        }
        return true;
    }

    function _stripos($source, $element)
    {
        return (strpos(strtolower($element), strtolower($source)));
    }
  
}
?>